
/**
 * 购买，赎回，到账
 */
class State{
    buy(){
        throw new Error("buy")
    }
    redeem(){
        throw new Error("redeem")
    }
    getMoney(){
        throw new Error("getMoney")
    }
}

class Buy extends State{
    constructor(operater){
        super()
        this.operater = operater
    }
    buy(){
        console.log("已经购买")
        this.operater.setState(this.operater.getRedeemState())
    }
    redeem(){
        console.log("请先购买")
    }
    getMoney(){
        console.log("请先赎回")
    }
}
class Redeem extends State{
    constructor(operater){
        super()
        this.operater = operater
    }
    buy(){
        console.log("已经购买")
    }
    redeem(){
        console.log("已经赎回")
        this.operater.setState(this.operater.getMoneyState())
    }
    getMoney(){
        console.log("请先赎回")
    }
}
class Money extends State{
    constructor(operater){
        super()
        this.operater = operater
    }
    buy(){
        console.log("已经购买")
    }
    redeem(){
        console.log("已经赎回")
    }
    getMoney(){
        console.log("已经获取资金")
        this.operater.setState(this.operater.getBuyState())
    }
}
/***
//  * 操控者
 */
class Operater extends State{
    constructor(){
        super()
        this.buy1 = new Buy(this)
        this.redeem1 = new Redeem(this)
        this.money = new Money(this)
        this.currentState = this.buy1
    }
    setState(state){
        this.currentState = state
    }
    getRedeemState(){
        return this.redeem1
    }
    getBuyState(){
        return this.buy1
    }
    getMoneyState(){
        return this.money
    }
    buy(){
        this.currentState.buy()
    }
    redeem(){
        this.currentState.redeem()
    }
    getMoney(){
        this.currentState.getMoney()
    }

}
const operater = new Operater()
// operater.buy()
// operater.redeem()
// operater.getMoney()



